package configuration

import (
	"encoding/json"
	"fmt"
	"kop/modules/achievement/configuration/a_type"
	"kop/modules/configuration/client"
	"kop/util/log"
)

var (
	Configs []Conf
)

func init() {

	if err := json.Unmarshal(client.Load("QuestAchieve"), &Configs); err != nil {
		panic(err)
	}

	log.Info("Load QuestAchieve.json success.")
}

//
type Conf struct {
	ID      int32
	Type    a_type.Type `json:"CheckType"`
	Value   int64
	Point   int32 `json:"AchievePoint"` // 参数2 具体ID
	AwardID int32 // 奖励ID
}

func GetByAchievementID(ID int32) Conf {

	for _, conf := range Configs {
		if conf.ID == ID {
			return conf
		}
	}

	panic(fmt.Errorf("AchieveID not found [%d]", ID))
}

func GetIDsByType18() []int32 {

	var res []int32

	for _, conf := range Configs {
		if conf.Type == a_type.FinishNum {
			res = append(res, conf.ID)
		}
	}

	return res
}
